<template>
	<view class="mySetting">
		<view class="center-box">
			<view class="item-box">
				<view class="name">
					位置
				</view>
				<view class="right-box">
					<fui-rate @change="wzrateChange" size='30'></fui-rate>
					<text class="rate-text">{{form.wzdf?form.wzdf+'.0':" "}}</text>
				</view>
			</view>
			<view class="item-box">
				<view class="name">
					设施
				</view>
				<view class="right-box">
					<fui-rate @change="ssrateChange" size='30'></fui-rate>
					<text class="rate-text">{{form.ssdf?form.ssdf+'.0':" "}}</text>
				</view>
			</view>
			<view class="item-box">
				<view class="name">
					服务
				</view>
				<view class="right-box">
					<fui-rate @change="fwrateChange" size='30'></fui-rate>
					<text class="rate-text">{{form.fwdf?form.fwdf+'.0':" "}}</text>
				</view>
			</view>
			<view class="item-box">
				<view class="name">
					卫生
				</view>
				<view class="right-box">
					<fui-rate @change="wsrateChange" size='30'></fui-rate>
					<text class="rate-text">{{form.wsdf?form.wsdf+'.0':" "}}</text>
				</view>
			</view>
			<view class="item-box">
				<view class="name">
					星级
				</view>
				<view class="right-box">
					<fui-rate @change="xjrateChange" size='30'></fui-rate>
					<text class="rate-text">{{form.xj?form.xj+'.0':" "}}</text>
				</view>
			</view>
			<view class="text-box">
				<textarea style="width: 100%;height: 100%;" v-model="form.text" placeholder-style="font-size: 26rpx;color: #A7A7A7;" cols="30" rows="10" placeholder="请输入您的评价…"></textarea>
			</view>
			<view class="image-box">
				<image :src="baseOssUrl2 + item" v-for="(item,index) in form.images" :key="index" class="image-item" @longpress='deleteImage(item,index)'></image>
				<view class="addImage" @click="onChooseavatar()" v-if="form.images.length<6">
					<image src="../../static/images/add.png" mode="" class="add"></image>
				</view>
			</view>
		</view>
		<view class="out-box">
			<view class="bnt-box" @click="add">
				评价
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		baseOssUrl,
		baseApiUrl,
		baseOssUrl2
	} from '@/common/settings';
	export default {
		//登录状态
		computed: mapState(['isLogin']),
		data() {
			return {
				userInfo: {},
				form :{
					images:[],
					text:'', // 内容 
					xj: '',// 打分星级
					wzdf:'',// 位置打分
					ssdf:'',// 设施打分
					fwdf:'',// 服务打分
					wsdf:'',// 卫生打分
					mId:'' ,//酒店id
					oId:''
				},
				baseOssUrl: baseOssUrl,
				baseApiUrl:baseApiUrl,
				baseOssUrl2:baseOssUrl2,
			}
		},
		onLoad(e) {
			this.form.mId = e.id
			this.form.oId = e.oid
		},
		methods: {
			...mapMutations(['login', 'logout']),
			onChooseavatar(e) {
				uni.chooseImage({
					count: 9, //默认9
					sizeType: 'compressed', //可以指定是原图还是压缩图，默认二者都有
					success: res => {
						uni.showLoading({
							title: '加载中'
						});
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							const tempFilePaths = res.tempFilePaths[i]
							uni.uploadFile({
								url: this.baseApiUrl  + '/x/sys/oss/upload',
								filePath: tempFilePaths,
								name: 'file',
								header: {
									'token': uni.getStorageSync('yc_m_token'),
								},
								success: (uploadFileRes) => {
									console.log(uploadFileRes, 'uploadFileRes')
									var imgurl = JSON.parse(uploadFileRes.data).url
									this.form.images.push(imgurl)
									uni.hideLoading();
								}
							});
						}
					}
				})
			},
			//长按删除
			deleteImage(item, index) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '是否删除该图片',
					success: function(res) {
						if (res.confirm) {
							that.form.images.splice(index, 1)
						} else if (res.cancel) {
							
						}
					}
				});
			},
			add() {
				if(!this.form.wzdf) {
					uni.showToast({
						icon: 'none',
						title: '请进行位置打分!',
						duration: 2000
					});
					return
				}
				if(!this.form.ssdf) {
					uni.showToast({
						icon: 'none',
						title: '请进行设施打分!',
						duration: 2000
					});
					return
				}
				if(!this.form.fwdf) {
					uni.showToast({
						icon: 'none',
						title: '请进行服务打分!',
						duration: 2000
					});
					return
				}
				if(!this.form.wsdf) {
					uni.showToast({
						icon: 'none',
						title: '请进行卫生打分!',
						duration: 2000
					});
					return
				}
				if(!this.form.xj) {
					uni.showToast({
						icon: 'none',
						title: '请进行星级打分!',
						duration: 2000
					});
					return
				}
				if(!this.form.text) {
					uni.showToast({
						icon: 'none',
						title: '进行描述!',
						duration: 2000
					});
					return
				}
				var images = this.form.images.toString()
				this.$http.post(this.$httpApi.orderevaluationsave + "?images=" + images + "&text=" + this.form.text + "&xj=" + this.form.xj + "&wzdf=" + this.form.ssdf + "&fwdf=" + this.form.fwdf + "&wsdf=" + this.form.wsdf + "&mId=" + this.form.mId + "&oId=" + this.form.oId + "&uId=" + uni.getStorageSync('userinfo').userId ).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '评价成功！',
							duration: 2000
						});
						setTimeout(res=>{
							uni.navigateBack(-1)
						},1000)
					}
				})
			},
			// 位置打分
			wzrateChange(e) {
				this.form.wzdf = e.score
			},
			// 设施打分
			ssrateChange(e) {
				this.form.ssdf = e.score
			},
			// 服务打分
			fwrateChange(e) {
				this.form.fwdf = e.score
			},
			// 卫生打分
			wsrateChange(e) {
				this.form.wsdf = e.score
			},
			// 星级打分
			xjrateChange(e) {
				this.form.xj = e.score
			}
		}
	}
</script>
<style>   page {     background: #EFEFEF;  } </style>
<style lang="scss" scoped>
	.mySetting {
		height: 100%;
		padding: 24rpx 32rpx 32rpx 32rpx;
		.center-box {
			padding: 33rpx 24rpx 30rpx 24rpx;
			border-radius: 8rpx ;
			background-color: #ffffff;
			.item-box {
				display: flex;
				align-items: center;
				margin-bottom: 18rpx;
				.name {
					font-size: 28rpx;
					color: #1D1D1D;
				}
				.right-box {
					display: flex;
					align-items: center;
					margin-left: auto;
					width: 502rpx;
					height: 64rpx;
					border-radius: 8rpx;
				}
			}
			.image-box {
				margin-top: 54rpx;
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				.image-item {
					margin-top: 20rpx;
					margin-right: 26rpx;
					width: 170rpx;
					height: 170rpx;
					background: #E6E6E6;
					border-radius: 8rpx;
				}
				.addImage {
					margin-top: 20rpx;
					width: 170rpx;
					height: 170rpx;
					background: #E6E6E6;
					border-radius: 8rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					.add {
						width: 50rpx;
						height: 50rpx;
					}
				}
			}
			.text-box {
				padding: 24rpx;
				margin-top: 6rpx;
				height: 368rpx;
				background: #F5F5F5;
				border-radius: 8rpx;
			}
		}
		.out-box {
			margin-top: 90rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			.bnt-box {
				width: 686rpx;
				height: 72rpx;
				background: #35743D;
				border-radius: 50rpx;
				text-align: center;
				line-height: 72rpx;
				font-weight: 500;
				color: #FFFFFF;
			}
		}
	}
	.rate-text {
		color: #EDBD0B;
		margin: 0 16rpx;
	}
</style>
